package com.atguigu.dao.Impl;

import com.atguigu.dao.BaseDao;
import com.atguigu.dao.OrderDao;
import com.atguigu.pojo.Order;

import java.util.List;

/**
 * @ClassName OrderDaoImpl
 * @Description TODO
 * @Author 周轩霆
 * @Date 2022/4/28 18:37
 **/

public class OrderDaoImpl extends BaseDao implements OrderDao {
    @Override
    public int saveOrder(Order order) {
        String sql = "insert into t_order(order_id,create_time,price,status,user_id) " +
                "values(?,?,?,?,?) ";
        return update(sql, order.getOrderId(), order.getCreateTime(), order.getPrice(), order.getStatus(), order.getUserId());

    }

    @Override
    public List<Order> queryOrders() {
        String sql = "select order_id orderId,create_time createTime,price,`status`,user_id userId from t_order";
//实体类和数据库中不同的字段应该加别名，否则查出来都是NULL。
        return queryForList(Order.class, sql);
    }

    /**
     * @return void
     * @Author 周轩霆
     * @Description 更改订单状态
     * @Date 10:57 2022/4/30
     * @Param [orderId, status]
     */
    @Override
    public int changeOrderStatus(String orderId, int status) {
        //修改订单状态，和订单号一一对应
        String sql = "update t_order set `status` = ? where order_id  = ?";
        Order order = new Order(orderId, null, null, status, null);
        return update(sql, order.getStatus(),order.getOrderId());

    }


}